<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:pe="http://primefaces.org/ui/extensions"
	xmlns:fc="http://fctracker.com/facelets"
	xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>

<h:body>
	<h:outputStylesheet library="css" name="foodJournal.css" />
	<h1>Étel napló</h1>
	<h:form id="foodJournalForm">
		<p:schedule id="schedule" value="#{foodJournalController.eventModel}"
			locale="hu" widgetVar="foodScheduleWidget">
			<p:ajax event="dateSelect"
				listener="#{foodJournalController.onDateSelect}"
				update=":createDialog"
				oncomplete="PF('foodCreateDialogWidget').show()" />
			<p:ajax event="eventSelect"
				listener="#{foodJournalController.onEventSelect}"
				update=":detailsDialog"
				oncomplete="PF('foodDetailsDialogWidget').show()" />
			<p:ajax event="eventMove"
				listener="#{foodJournalController.onEventMove}" />
		</p:schedule>
	</h:form>

	<p:dialog id="createDialog" widgetVar="foodCreateDialogWidget"
		closeOnEscape="true" resizable="false" header="Új bejegyzés"
		showEffect="clip" hideEffect="clip">
		<h:form>
			<h:panelGrid id="createDetails" columns="2">
				<p:outputLabel for="food" value="Recept" />
				<p:selectOneMenu id="food"
					value="#{foodJournalController.entry.recipe}">
					<f:selectItems value="#{foodJournalController.findRecipes()}"  />
					<f:converter binding="#{recipeConverter}" />
				</p:selectOneMenu>

				<p:outputLabel for="from" value="Mikor" />
				<p:calendar id="from" value="#{foodJournalController.entry.date}"
					locale="hu" stepMinute="15" pattern="yyyy.MM.dd HH:mm" showButtonPanel="true" />

				<p:outputLabel for="quantity" value="Mennyit" />
				<pe:inputNumber id="quantity" decimalPlaces="0" maxValue="99"
					symbolPosition="s" value="#{foodJournalController.entry.quantity}" />
			</h:panelGrid>
			<p:commandButton id="addButton" value="Mentés" icon="ui-icon-disk"
				actionListener="#{foodJournalController.addEvent}"
				onsuccess="PF('foodScheduleWidget').update();PF('foodCreateDialogWidget').hide();">
			</p:commandButton>
		</h:form>
	</p:dialog>

	<p:dialog id="detailsDialog" widgetVar="foodDetailsDialogWidget"
		showEffect="clip" hideEffect="clip" closeOnEscape="true"
		resizable="false" width="800" height="500"
		header="#{foodJournalController.readonlyEntry.dateString} - #{foodJournalController.readonlyEntry.recipe.name} - #{foodJournalController.readonlyEntry.quantity} adag">

		<fc:recipeData recipe="#{foodJournalController.readonlyEntry.recipe}" />
		<h:form>
			<p:commandButton id="removeButton" value="Törlés"
				icon="ui-icon-trash"
				actionListener="#{foodJournalController.delete(foodJournalController.readonlyEntry)}"
				onsuccess="PF('foodScheduleWidget').update();PF('foodDetailsDialogWidget').hide();">
			</p:commandButton>
		</h:form>
	</p:dialog>
</h:body>
</html>